'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE, TEXT } = app.Sequelize;

  const Test = app.model.define('test', {
    id: { 
      type: INTEGER, 
      primaryKey: true, 
      autoIncrement: true,
      allowNull: false
    },
    // 试卷名
    title: {
      type: STRING,
      allowNull: false
    },
    // 完成时间（默认90分钟）
    timelimit: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 90
    },
    // 截止时间
    deadline: {
      type: DATE,
      allowNull: false
    },
    // 问题
    questions: {
      type: TEXT,
      allowNull: false
    },
    created_at: DATE,
    updated_at: DATE
  })
  Test.associate = function () {
    app.model.Test.belongsToMany(app.model.User, {
      through: app.model.TestUser,
      foreignKey: 'test_id',
      otherKey: 'user_id'
    })
  }
  return Test;
};


